#ifndef MDTX_USE_RCPPARMADILLO
#define MDTX_USE_RCPPARMADILLO
#endif

#include <RcppArmadillo.h>
using namespace Rcpp;

#include "mdtx-online/aggregator/aggregator_type_vol.h"
#include "mdtx-online/aggregator/aggregator_type_tnvr.h"
using namespace mdtx::online;

#include "aggr_common.h"

using volclk_ohlcv_ = aggr<false,
                           aggregator::volclk_ohlcv<double>,
                           IntegerVector,
                           NumericVector>;

//' Aggregate market orders to volume clock
//'
//' @param price Numeric vector Price
//' @param volume Numeric vector Volume
//' @param turnover Numeric vector Turnover
//' @param volume_bin_size volume clock bin size
//' @return List of nbin (number of bin), open, high, low, close, vwap
//' @export
// [[Rcpp::export(rng = false)]]
List volclk_ohlcv(NumericVector price, NumericVector volume, NumericVector turnover, double volume_bin_size)
{
    auto c = volclk_ohlcv_::create(volume_bin_size);
    return volclk_ohlcv_::run_ohlcv5(c, price, volume, turnover);
}

// [[Rcpp::export(rng = false)]]
SEXP volclk_ohlcv_new(double volume_bin_size)
{
    return volclk_ohlcv_::create(volume_bin_size);
}

// [[Rcpp::export(rng = false)]]
List volclk_ohlcv_run(SEXP ptr, NumericVector price, NumericVector volume, NumericVector turnover)
{
    return volclk_ohlcv_::run_ohlcv5(ptr, price, volume, turnover);
}

using volclk_vwap_ = aggr<false,
                          aggregator::volclk_vwap<double>,
                          IntegerVector,
                          NumericVector>;

//' Aggregate market orders to volume clock vwap
//'
//' @param price Numeric vector Price
//' @param volume Numeric vector Volume
//' @param turnover Numeric vector Turnover
//' @param volume_bin_size volume clock bin size
//' @return List of nbin (number of bin), vwap
//' @export
// [[Rcpp::export(rng = false)]]
List volclk_vwap(NumericVector price, NumericVector volume, NumericVector turnover, double volume_bin_size)
{
    auto c = volclk_vwap_::create(volume_bin_size);
    return volclk_vwap_::run_ohlcv1(c, price, volume, turnover);
}

// [[Rcpp::export(rng = false)]]
SEXP volclk_vwap_new(double volume_bin_size)
{
    return volclk_vwap_::create(volume_bin_size);
}

// [[Rcpp::export(rng = false)]]
List volclk_vwap_run(SEXP ptr, NumericVector price, NumericVector volume, NumericVector turnover)
{
    return volclk_vwap_::run_ohlcv1(ptr, price, volume, turnover);
}

using volume_bar_ = aggr<false,
                         aggregator::volume_bar<double>,
                         IntegerVector,
                         NumericVector>;

//' Aggregate market orders to volume bar
//'
//' @param price Numeric vector Price
//' @param volume Numeric vector Volume
//' @param turnover Numeric vector Turnover
//' @param volume_bin_size volume bin size
//' @return List of open, high, low, close, vol, tnvr, vwap
//' @export
// [[Rcpp::export(rng = false)]]
List volume_bar(NumericVector price, NumericVector volume, NumericVector turnover, double volume_bin_size)
{
    auto c = volume_bar_::create(volume_bin_size);
    return volume_bar_::run_ohlcv7(c, price, volume, turnover);
}

// [[Rcpp::export(rng = false)]]
SEXP volume_bar_new(double volume_bin_size)
{
    return volume_bar_::create(volume_bin_size);
}

// [[Rcpp::export(rng = false)]]
List volume_bar_run(SEXP ptr, NumericVector price, NumericVector volume, NumericVector turnover)
{
    return volume_bar_::run_ohlcv7(ptr, price, volume, turnover);
}

using tnvrclk_ohlcv_ = aggr<false,
                            aggregator::tnvrclk_ohlcv<double>,
                            IntegerVector,
                            NumericVector>;

//' Aggregate market orders to turnover clock
//'
//' @param price Numeric vector Price
//' @param volume Numeric vector Volume
//' @param turnover Numeric vector Turnover
//' @param turnover_bin_size turnover clock bin size
//' @return List of nbin (number of bin), open, high, low, close, vwap
//' @export
// [[Rcpp::export(rng = false)]]
List tnvrclk_ohlcv(NumericVector price, NumericVector volume, NumericVector turnover, double turnover_bin_size)
{
    auto c = tnvrclk_ohlcv_::create(turnover_bin_size);
    return tnvrclk_ohlcv_::run_ohlcv5(c, price, volume, turnover);
}

// [[Rcpp::export(rng = false)]]
SEXP tnvrclk_ohlcv_new(double turnover_bin_size)
{
    return tnvrclk_ohlcv_::create(turnover_bin_size);
}

// [[Rcpp::export(rng = false)]]
List tnvrclk_ohlcv_run(SEXP ptr, NumericVector price, NumericVector volume, NumericVector turnover)
{
    return tnvrclk_ohlcv_::run_ohlcv5(ptr, price, volume, turnover);
}

using tnvrclk_vwap_ = aggr<false,
                           aggregator::tnvrclk_vwap<double>,
                           IntegerVector,
                           NumericVector>;

//' Aggregate market orders to turnover clock vwap
//'
//' @param price Numeric vector Price
//' @param volume Numeric vector Volume
//' @param turnover Numeric vector Turnover
//' @param turnover_bin_size turnover clock bin size
//' @return List of nbin (number of bin), vwap
//' @export
// [[Rcpp::export(rng = false)]]
List tnvrclk_vwap(NumericVector price, NumericVector volume, NumericVector turnover, double turnover_bin_size)
{
    auto c = tnvrclk_vwap_::create(turnover_bin_size);
    return tnvrclk_vwap_::run_ohlcv1(c, price, volume, turnover);
}

// [[Rcpp::export(rng = false)]]
SEXP tnvrclk_vwap_new(double turnover_bin_size)
{
    return tnvrclk_vwap_::create(turnover_bin_size);
}

// [[Rcpp::export(rng = false)]]
List tnvrclk_vwap_run(SEXP ptr, NumericVector price, NumericVector volume, NumericVector turnover)
{
    return tnvrclk_vwap_::run_ohlcv1(ptr, price, volume, turnover);
}

using turnover_bar_ = aggr<false,
                           aggregator::turnover_bar<double>,
                           IntegerVector,
                           NumericVector>;

//' Aggregate market orders to dollar bar
//'
//' @param price Numeric vector Price
//' @param volume Numeric vector Volume
//' @param turnover Numeric vector Turnover
//' @param turnover_bin_size turnover bin size
//' @return List of open, high, low, close, vol, tnvr, vwap
//' @export
// [[Rcpp::export(rng = false)]]
List turnover_bar(NumericVector price, NumericVector volume, NumericVector turnover, double turnover_bin_size)
{
    auto c = turnover_bar_::create(turnover_bin_size);
    return turnover_bar_::run_ohlcv7(c, price, volume, turnover);
}

// [[Rcpp::export(rng = false)]]
SEXP turnover_bar_new(double turnover_bin_size)
{
    return turnover_bar_::create(turnover_bin_size);
}

// [[Rcpp::export(rng = false)]]
List turnover_bar_run(SEXP ptr, NumericVector price, NumericVector volume, NumericVector turnover)
{
    return turnover_bar_::run_ohlcv7(ptr, price, volume, turnover);
}
